<template>
	<view class="main">
		<view class="about">
			<view class="q">
				会员权益
			</view>
			<view class="h">
				<view class="h_h">
					<view class="h_left_left">
						<image src="@/static/mf.svg" mode=""></image>
					</view>
					<view class="h_right_right">
						<view class="s">
							免费观看
						</view>
						<view class="x">
							付费内容享受免费观看
						</view>
					</view>
				</view>
				<view class="h_h">
					<view class="h_left_left">
						<image src="@/static/huojian.svg" mode=""></image>
					</view>
					<view class="h_right_right">
						<view class="s">
							新剧优先观看
						</view>
						<view class="x">
							新剧会员可优先观看
						</view>
					</view>
				</view>
			</view>
			<view class="g">
				劲爆会员活动，<text>最低0.16元/天！</text>
			</view>
			<view class="v">
				<view class="box" v-for="(v,k) in Member" :key="k"
					 @click="dian(v)">
					<view class="tishi" v-if="![8, 13].includes(v.type)">
						<image src="@/static/new-vip.png"></image>
					</view>
					<view class="price">
						{{v.money}}{{v.currency_type}}
					</view>
					<view class="box-day" v-if="![8, 13].includes(v.type)">
						全场剧免费看{{v.day}}天
					</view>
					<view class="box-day" v-else-if="v.type==8">
						{{(parseFloat(v.money) * 100).toFixed(0)}}书币+赠送{{v.send_gold}}书币
					</view>
					<view class="box-day" v-else-if="v.type === 13">
						解锁本剧免费看
					</view>
					<view class="box-footer" v-if="![8, 13].includes(v.type)">
						{{k==0?"85%用户选择":v.subscript==='超值'||v.subscript==='限时' ? '限时超值优惠':v.subscript }}
					</view>
					<view class="box-footer" v-else>
						{{v.title === '单本解锁' ?'免费看本剧': v.title}}
					</view>
					
				</view>
			</view>
            <PurchaseNotes/>
			<view class="dibu">
				<view class="hy" @click="goxieyi">《会员协议》</view>
			</view>
		</view>
	</view>
</template>

<script>
	import PurchaseNotes from "@/components/purchase-notes.vue"
	import {
		Users
	} from "@/request/api.js"
	import {
		open_from
	} from "@/request/open_from.js"
	import { handleMember } from '@/common/Newapp.js'
	
	export default {
		components:{
			PurchaseNotes
		},
		data() {
			return {
				osName: uni.getStorageSync('osName'),
				yi: 0, //9.9
				Member: [],
				Recharge: {
					recharge_id: "",
					book_id: '0',
					fromtype: '1',
					pay_way: '1',
					pay_type: '55',
					money: '',
					is_cont: '2',
					keyword_id: 0,
					recharge_type: 1
				},
			}
		},
		async onLoad() {
			this.Recharge.pay_type = open_from
			let keywords = uni.getStorageSync('keywords')
			//判断是否是在投放24小时内
			if(uni.getStorageSync('keywords')){
				this.Recharge.keyword_id = uni.getStorageSync('keywords') || 0
			}else{
				this.Recharge.keyword_id = 0
			}
			let res = await Users.Memberlist({
				passphrases: keywords ? keywords : '0',
				operating_system_type:this.osName == 'ios' ? 2 : 1
			})
			if (res.status_code == 200) {
				this.Member = res.data.filter((item) => {
					return item.recharge_way !== 2
				})
				this.Member = handleMember(this.Member)
			}
		},
		methods: {
			// 选择会员价格
			dian(v) {
				this.Recharge.recharge_type = v.type
				this.Recharge.money = this.osName == 'ios' ? v.money / 10 : v.money
				this.Recharge.recharge_id = v.id
				this.buy()
			},
			//购买会员
			async buy() {
				if (this.osName == 'ios') {
					this.Recharge.is_ios = 1
				}
				this.Recharge.fromtype = this.Recharge.keyword_id == 0 ? '1' : '4'
				let res = await Users.Recharge(this.Recharge)
				uni.showLoading({
					title: '加载中',
				})
				setTimeout(() => {
					uni.hideLoading()
				}, 2000)
				if (res.status_code !== 200) {
					this.$u.toast('发生错误，请稍后重试')
					return
				}
				let that = this
				tt.requestOrder({
					data: res.data.data.data,
					byteAuthorization: res.data.data.byteAuthorization,
					success(order) {
						// 苹果用户传入Im客服id,安卓不传
						let params = {
							orderId: order.orderId,
						}
						if (that.osName == 'ios') {
							params.imId = '39477054051'
						}
						tt.getOrderPayment({
							...params,
							success(payment) {
								setTimeout(() => {
									uni.switchTab({
										url: "/pages/User/User"
									})
								}, 1000)
							},
							fail(err1) {
								console.log(err1)
							}
						})
					},
					fail(err) {
						that.$u.toast('订单出错')
					}
				})
			},
			goxieyi() {
				uni.navigateTo({
					url: "/pages/Agreement/Agreement"
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	@import url("./Member.less");
</style>